package com.meilai.project.controller.web.business.workbench;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.meilai.project.dto.CommonResult;
import com.meilai.project.dto.business.workbench.FillWeekCustomerTargetDTO;
import com.meilai.project.dto.business.workbench.SigningTimeDTO;
import com.meilai.project.dto.business.workbench.VisitRecordDTO;
import com.meilai.project.service.business.workbench.SaleMonthService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/api/web/saleMonth")
public class SaleMonthController {

    @Autowired
    private SaleMonthService service;

    @GetMapping("/queryThisMonthTarget")
    @ApiOperation("根据type查询本月目标数据")
    public CommonResult queryThisMonthTargetData(@RequestParam("type") Integer type) {
        return new CommonResult().success(service.queryThisMonthTargetData(type));
    }

    @PostMapping("/addOrEditSigningTime")
    @ApiOperation("添加签约时间")
    public CommonResult addSigningTime(@RequestBody SigningTimeDTO dto) {
        return new CommonResult().success(service.addOrEditSigningTime(dto));
    }

    @PostMapping("/saveMonthCustomerTarget")
    @ApiOperation("保存月度的客户目标")
    public CommonResult saveThisMonthCustomerTarget(@RequestBody List<FillWeekCustomerTargetDTO> dtoList) {
        return new CommonResult().success(service.saveThisMonthCustomerTarget(dtoList));
    }

    @PostMapping("/addVisitRecord")
    @ApiOperation("添加跟进记录")
    public CommonResult addVisitRecord(@RequestBody VisitRecordDTO dto) {
        return new CommonResult().success(service.addVisitRecord(dto));
    }

    @GetMapping("/signatureHistoryList")
    @ApiOperation("签约历史列表")
    public CommonResult signatureHistoryList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                             @RequestParam(value = "page_size", defaultValue = "10") Integer page_size,
                                             @RequestParam("customer_id") Long customer_id,
                                             @RequestParam(value = "begin_date", required = false) @JsonFormat(pattern = "yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin_date,
                                             @RequestParam(value = "end_date", required = false) @JsonFormat(pattern = "yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end_date) {
        return new CommonResult().success(service.signatureHistoryList(page, page_size, customer_id, begin_date, end_date));
    }

    @GetMapping("/nextMonthTarget")
    @ApiOperation("下个月的数据")
    public CommonResult nextMonthTarget(@RequestParam("type") Integer type) {
        return new CommonResult().success(service.nextMonthTarget(type));
    }

    @PostMapping("/confirmReceive")
    @ApiOperation("确认收到")
    public CommonResult confirmReceive(@RequestParam("id") Long id) {
        return new CommonResult().success(service.confirmReceive(id));
    }
}
